/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package L2win;

import Unit.Element;
import java.util.ArrayList;

/**
 *
 * @author tuyentran
 */
public class L2winChainNode {
    private Element core;
    private L2winChainNode relative;
    private ArrayList<Element> corChain = new ArrayList<Element>();

    public L2winChainNode(Element core){
        this.core = core;
    }
    
    public L2winChainNode(Element core, ArrayList<Element> corChain){
        this.core = core;
        this.corChain = corChain;
    }
    
    /**
     * @return the core
     */
    public Element getCore() {
        return core;
    }

    /**
     * @param core the core to set
     */
    public void setCore(Element core) {
        this.core = core;
    }

    /**
     * @return the relative
     */
    public L2winChainNode getRelative() {
        return relative;
    }

    /**
     * @param relative the relative to set
     */
    public void setConnect(L2winChainNode node) {
        this.relative = node;
    }
    
    /**
     * @function get left chain from this object
     */
    public ArrayList<Element> getLeftChain() {
        ArrayList<Element> result = new ArrayList<Element>();
        result.add(core);
        L2winChainNode cur = this;
        while (cur.getRelative()!=null){
            result.add(cur.getRelative().getCore());
            cur = cur.getRelative();
        }
        return result;
    }

    /**
     * @function get right chain from this object
     */
    public ArrayList<Element> getRightChain() {
        ArrayList<Element> result = new ArrayList<Element>();
        result.add(core);
        L2winChainNode cur = this;
        while (cur.getRelative()!=null){
            result.add(0,cur.getRelative().getCore());
            cur = cur.getRelative();
        }
        return result;
    }

    /**
     * @return the corChain
     */
    public ArrayList<Element> getCorChain() {
        return corChain;
    }
    
    /**
     * @function add e to corChain
     * @param e 
     */
    public void addToCorChain(Element e) {
        getCorChain().add(e);
    }

}
